home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap6 / 6_3 / dirln_c / handler.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  1.6 KB  |  71 lines

  1.  
  2. #include "handler.h"
  3.  
  4.  
  5. void directiveHandler(String ts,String as,String et,Dictionary td)
  6. {
  7.     String argString = 0;
  8.     String endTag = 0;
  9.     String type;
  10.     void (*handler)();
  11.     
  12.     type = dict_valueForKey(td,"TYPE");
  13.     
  14.     if(type->string)
  15.     {
  16.         String registeredType;
  17.         
  18.         registeredType = string_alloc(strlen(type->string));
  19.         
  20.         string_setStringValue(registeredType , "directive."); 
  21.         string_appendString(registeredType , type->string); 
  22.     
  23.         /* See if there is an endtag or a handler registered*/
  24.         endTag = dict_valueForKey(endTags, registeredType->string);
  25.         
  26.         handler = dict_valueForKey(handlerDict, registeredType->string);
  27.         
  28.         string_free(registeredType);
  29.     }
  30.     
  31.     /* If there is a handler, use it */
  32.     if(handler)
  33.     {
  34.         /* If there is an end tag, parse up to it
  35.          * be sure to remove the end tag from the body text.
  36.          */
  37.         if(endTag && endTag->string)
  38.         {
  39.             char * finalPointy = 0;
  40.             
  41.             argString = mainHtmlParser(endTag->string);
  42.             
  43.             /* Get rid of the end tag */
  44.             
  45.             if(endTag->string[0] == '<')/* this is a real tag */
  46.             {
  47.                 finalPointy = strrchr(argString->string,'<');
  48.                 
  49.                 /* End the string at the final <, thus removing the end tag */
  50.                 if(finalPointy) *finalPointy = '\0';
  51.             }
  52.         }
  53.         
  54.         /* Call the handler */
  55.         handler(ts,argString,endTag,td);
  56.     }
  57.     else /* No handler, treat this as plain text */
  58.     {
  59.         string_setStringValue(ts,"");
  60.     }
  61.     
  62.     /* Clean up */
  63.     string_free(argString);
  64. }
  65.  
  66. void webmasterHandler(String ts,String as,String et,Dictionary td)
  67. {
  68.     /* Set the tag string to the link that we want inserted */
  69.     string_setStringValue(ts,"<A HREF=\"mailto:joe@webmastersrus.com\">joe@webmastersrus.com</A>");
  70. }
  71.